"Playing" with Word

Hi,

I'm working on a program which will read a CR from a Microsoft Word table (The table will have the DOORS ID numbers and attribute names in the first row).  I am planning on taking the values for each row in the table and updating the objects that are listed in the table.  I already know how to open the file in Word, I'm just struggling with how I could read the table, row by row and then store the value of each cell in a variable so that I can update the changed attributes in DOORS.

Thanks


josiah820 - Tue May 28 15:03:05 EDT 2013

Re: "Playing" with Word
llandale - Tue May 28 17:01:42 EDT 2013

You need a "Table" handle.  Get a "Tables" handle from the "Document" handle, then use argument "1" to get the "Table" from the "Tables".

Get a "Cell" handle from the "Table".  Use arguments "RowNum" and "ColumnNum" in method "GetCell" (i think).

Get the "Text" property of the "Cell"; and deal with it based on which "column" you are dealing with.

-Louie

I've been "playing" lately also.  The closer I climb to the horizon the further away it gets.

Re: "Playing" with Word
josiah820 - Wed May 29 08:07:45 EDT 2013

llandale - Tue May 28 17:01:42 EDT 2013

You need a "Table" handle.  Get a "Tables" handle from the "Document" handle, then use argument "1" to get the "Table" from the "Tables".

Get a "Cell" handle from the "Table".  Use arguments "RowNum" and "ColumnNum" in method "GetCell" (i think).

Get the "Text" property of the "Cell"; and deal with it based on which "column" you are dealing with.

-Louie

I've been "playing" lately also.  The closer I climb to the horizon the further away it gets.

Thanks, I think I get it!

And I totally agree with you!  I never thought that there would be a language that would make me miss programming in Java!

Re: "Playing" with Word
josiah820 - Wed May 29 12:41:14 EDT 2013

llandale - Tue May 28 17:01:42 EDT 2013

You need a "Table" handle.  Get a "Tables" handle from the "Document" handle, then use argument "1" to get the "Table" from the "Tables".

Get a "Cell" handle from the "Table".  Use arguments "RowNum" and "ColumnNum" in method "GetCell" (i think).

Get the "Text" property of the "Cell"; and deal with it based on which "column" you are dealing with.

-Louie

I've been "playing" lately also.  The closer I climb to the horizon the further away it gets.

Okay, so I've been digging, and I can't find any information on exactly what kind of handles I would have to use.  Any ideas?  I know that you have been working with DOORS for longer than I have (I'm still pretty new, as in less than 6 months of DXL experience), so I figured you might have an idea of what kinds of variables/lines I should use.  I know I want to:

1) Count the number of cells in each row

2) Loop through each row, transferring the data cell by cell into the target module

I'm assuming that I will need an integer variable for the number of cells, a "for" loop (for(i = 0; i < (number of columns); i++)), a string variable to store the data of the current cell, a string variable to hold the DOORS ID number, and a string variable to hold the "column name" (which will be the name of the attribute that is being replaced), but I'm unclear as to how the loop should go and how I can get the value of the string from MS Word?

Thanks!

Re: "Playing" with Word
llandale - Wed May 29 13:29:27 EDT 2013

josiah820 - Wed May 29 12:41:14 EDT 2013

Okay, so I've been digging, and I can't find any information on exactly what kind of handles I would have to use.  Any ideas?  I know that you have been working with DOORS for longer than I have (I'm still pretty new, as in less than 6 months of DXL experience), so I figured you might have an idea of what kinds of variables/lines I should use.  I know I want to:

1) Count the number of cells in each row

2) Loop through each row, transferring the data cell by cell into the target module

I'm assuming that I will need an integer variable for the number of cells, a "for" loop (for(i = 0; i < (number of columns); i++)), a string variable to store the data of the current cell, a string variable to hold the DOORS ID number, and a string variable to hold the "column name" (which will be the name of the attribute that is being replaced), but I'm unclear as to how the loop should go and how I can get the value of the string from MS Word?

Thanks!

I've been talking about DOORS controlling the Word application with OLE Automation.  There are two primary DOORS data types; OleAutoObject and OleAutoArgs.  If you have no idea what I'm talking about then you are doomed.  You will need to browse forums and get a rough idea what is going on.  Code will look something like this:

  • OleAutoObject oaoApp, oaoDoc, oaoTables, oaoTable, oaoCell, oaoRange
  • OleAutArgs oaaArgs
  • oaaArgs = create
  • oaoApp = oleGet("word.application")
  • oleMethod(oaoApp, "Document", oaaArgs, oaoDoc)
  • oleGet   (oaoDoc, "Tables", oaoTables)
  • put(oaaArgs, 1)
  • oleMethod(oaoTables, "Table", oaaArgs, oaoTable)
  • clear(oaaArgs)
  • put(oaaArgs, "Row", 2)   // row 2
  • put(oaaArgs, "Column", 3) // column 3
  • oleMethod(oaoTable, "Cell", oaaArgs, oaoCell)
  • clear(oaaArgs)
  • oleGet(oaoCell, "Range", oaoRange)
  • string Text
  • oleGet(oaoRange, "Text", Text)
  • ... deal with the Text from cell(in row 2 col 3)
  • delete(oaaArgs)
  • oleCloseAutoObject(oaoApp)
  • oleCloseAutoObject(oaoDoc); etc

In VBA, I think all the above looks like this:

  • Set Text = ActiveDocument.Tables(1).Cell(Row:=2, Column:=3).Range.Text

I'm really struggling with this myself this month.

-Louie

Re: "Playing" with Word
josiah820 - Thu May 30 08:44:35 EDT 2013

llandale - Wed May 29 13:29:27 EDT 2013

I've been talking about DOORS controlling the Word application with OLE Automation.  There are two primary DOORS data types; OleAutoObject and OleAutoArgs.  If you have no idea what I'm talking about then you are doomed.  You will need to browse forums and get a rough idea what is going on.  Code will look something like this:

  • OleAutoObject oaoApp, oaoDoc, oaoTables, oaoTable, oaoCell, oaoRange
  • OleAutArgs oaaArgs
  • oaaArgs = create
  • oaoApp = oleGet("word.application")
  • oleMethod(oaoApp, "Document", oaaArgs, oaoDoc)
  • oleGet   (oaoDoc, "Tables", oaoTables)
  • put(oaaArgs, 1)
  • oleMethod(oaoTables, "Table", oaaArgs, oaoTable)
  • clear(oaaArgs)
  • put(oaaArgs, "Row", 2)   // row 2
  • put(oaaArgs, "Column", 3) // column 3
  • oleMethod(oaoTable, "Cell", oaaArgs, oaoCell)
  • clear(oaaArgs)
  • oleGet(oaoCell, "Range", oaoRange)
  • string Text
  • oleGet(oaoRange, "Text", Text)
  • ... deal with the Text from cell(in row 2 col 3)
  • delete(oaaArgs)
  • oleCloseAutoObject(oaoApp)
  • oleCloseAutoObject(oaoDoc); etc

In VBA, I think all the above looks like this:

  • Set Text = ActiveDocument.Tables(1).Cell(Row:=2, Column:=3).Range.Text

I'm really struggling with this myself this month.

-Louie

Got it! Thanks!  It figures that I just found out that this program (which was requested by someone on the DOORS Team) would require us to make a change to our entire change request process, which isn't going to happen... But thanks for your help! I'm sure I'll use that at some time in the near future!

Re: "Playing" with Word
dhars_priya - Mon May 25 06:22:57 EDT 2015

llandale - Wed May 29 13:29:27 EDT 2013

I've been talking about DOORS controlling the Word application with OLE Automation.  There are two primary DOORS data types; OleAutoObject and OleAutoArgs.  If you have no idea what I'm talking about then you are doomed.  You will need to browse forums and get a rough idea what is going on.  Code will look something like this:

  • OleAutoObject oaoApp, oaoDoc, oaoTables, oaoTable, oaoCell, oaoRange
  • OleAutArgs oaaArgs
  • oaaArgs = create
  • oaoApp = oleGet("word.application")
  • oleMethod(oaoApp, "Document", oaaArgs, oaoDoc)
  • oleGet   (oaoDoc, "Tables", oaoTables)
  • put(oaaArgs, 1)
  • oleMethod(oaoTables, "Table", oaaArgs, oaoTable)
  • clear(oaaArgs)
  • put(oaaArgs, "Row", 2)   // row 2
  • put(oaaArgs, "Column", 3) // column 3
  • oleMethod(oaoTable, "Cell", oaaArgs, oaoCell)
  • clear(oaaArgs)
  • oleGet(oaoCell, "Range", oaoRange)
  • string Text
  • oleGet(oaoRange, "Text", Text)
  • ... deal with the Text from cell(in row 2 col 3)
  • delete(oaaArgs)
  • oleCloseAutoObject(oaoApp)
  • oleCloseAutoObject(oaoDoc); etc

In VBA, I think all the above looks like this:

  • Set Text = ActiveDocument.Tables(1).Cell(Row:=2, Column:=3).Range.Text

I'm really struggling with this myself this month.

-Louie

I referred this code. I am getting error like objTable is empty..

I need to get the single celled content of table. could you check for this?